<template>
  <div>
    <!-- 标签或分类名 -->
    <div class="tag-banner banner">
      <h1 class="banner-title animated fadeInDown">{{ title }} - {{ name }}</h1>
    </div>
    <div class="article-list-wrapper">
      <v-row>
        <v-col md="3" cols="12" v-for="item of resList" :key="item.id">
          <!-- 文章 -->
          <v-card class="animated zoomIn article-item-card">
            <div @click="toDetails(item)"  class="article-item-cover" style="display: grid;grid-template-columns: repeat(auto-fill, 270px);">
                <!-- 缩略图 -->
                <v-img
                  class="on-hover"
                  width="100%"
                  height="100%" 
                  :src="item.pic"
                />
            </div>
            <div class="article-item-info">
              <!-- 文章标题 -->
              <div  @click="toDetails(item)" style="font-weight: bolder;">
                  {{ item.resName }}
              </div>
               <!-- 文章内容 -->
              <div @click="toDetails(item)" style="font-size: 13px;color: #909399;height: 50px;">
                {{ item.resDesc }}
              </div>
              <div style="margin-top:0.375rem;color: #909399;font-size: 13px;">
                <!-- 发表时间 -->
                <i class="el-icon-time"> {{item.issueTime}}</i>
                
                <!-- 文章分类 -->
                <router-link
                  :to="'/resource/details/' + item.id"
                  class="tag-btn float-right"
                  style="color:#fff;"
                >
                  {{ item.classify }}
                </router-link>
              </div>
            </div>
            <!-- 分割线 -->
            <v-divider></v-divider>
            <!-- 文章标签 -->
            <div class="tag-wrapper">
              
              <el-tooltip class="item" effect="dark" content="浏览" placement="top">
                <div @click="toDetails(item)" class="item"><i class="iconfont icon-attention"></i>
              {{item.views}}</div>
              </el-tooltip>

              <el-tooltip class="item" effect="dark" content="评论" placement="top">
                <div @click="toDetails(item)" class="item"><i class="iconfont icon-comment"> </i>
                {{item.comments}}</div>
              </el-tooltip>
             
              <el-tooltip  class="item" effect="dark" content="访问" placement="top">
                <div @click="visit(item)" class="item"><i class="iconfont icon-fangwen"> </i></div>
              </el-tooltip>
              
            </div>
          </v-card>
        </v-col>
      </v-row>
    </div>
    <el-pagination
      class="pagination"
      background
      layout="prev, pager, next"
      :total="params.total"
      @current-change="handleCurrentChange"
      :current-page.sync="params.current"
      :page-size="params.size">
    </el-pagination>
  </div>
</template>

<script>
import {pageByClassify,getClassifyName} from '../api/resource';
export default {
  created() {
    this.title = "资源";
    this.categoryOrTag = "tag-banner";
    const id = this.$route.path.split('/')[2];
    this.params.id=id;
    this.initClassifyName();
    this.infiniteHandler();
  },
  data: function() {
    return {
      params:{
        current:1,
        size:4,
        total:0,
        id:''
      },
      name: "",
      title: "",
      resList:[]
    };
  },
  methods: {
    
    infiniteHandler(){
      pageByClassify(this.params).then(res=>{
        if(res.data.code==200){
          this.resList=res.data.data.records;
          this.params.total=res.data.data.total;
          this.params.current=res.data.data.current;
          this.params.size=res.data.data.size;
        }
      })
    },
    handleCurrentChange(val) {
      this.params.current=val;
      this.infiniteHandler();
    },
    initClassifyName(){
      getClassifyName(this.params).then(res=>{
        if(res.data.code==200){
          this.name=res.data.data;
          document.title ='资源-'+ res.data.data;
        }
      })
    },
    visit(item){
      window.open(item.resLink,"_blank")
    },
    toDetails(item){
      window.open("/#/resource/details/"+item.id,'_blank');
    }
  }
};
</script>

<style scoped>
.item {
  flex: 1;
  font-size: 16px;
  text-align: center;
}
.pagination {
  margin-left: 45%;
  margin-bottom: 15px;
}
.tag-banner {
  background: url(https://static.talkxj.com/73lleo.png)
    center center / cover no-repeat;
  background-color: #49b1f5;
}
.category-banner {
  background: url(https://cdn.jsdelivr.net/gh/axh2018/axh2018.github.io/medias/banner/6.jpg)
    center center / cover no-repeat;
  background-color: #49b1f5;
}
@media (min-width: 760px) {
  .article-list-wrapper {
    max-width: 1106px;
    margin: 370px auto 1rem auto;
  }
  .article-item-card:hover {
    transition: all 0.3s;
    box-shadow: 0 4px 12px 12px rgba(7, 17, 27, 0.15);
  }
  .article-item-card:not(:hover) {
    transition: all 0.3s;
  }
  .article-item-card:hover .on-hover {
    transition: all 0.6s;
    transform: scale(1.1);
  }
  .article-item-card:not(:hover) .on-hover {
    transition: all 0.6s;
  }
  .article-item-info {
    line-height: 1.7;
    padding: 15px 15px 12px 18px;
    font-size: 15px;
  }
}
@media (max-width: 759px) {
  .article-list-wrapper {
    margin-top: 230px;
    padding: 0 12px;
  }
  .article-item-info {
    line-height: 1.7;
    padding: 15px 15px 12px 18px;
  }
}
.article-item-card {
  border-radius: 8px !important;
  box-shadow: 0 4px 8px 6px rgba(7, 17, 27, 0.06);
}
.article-item-card a {
  transition: all 0.3s;
}
.article-item-cover {
  height: 150px;
  overflow: hidden;
}
.article-item-card a:hover {
  color: #8e8cd8;
}
.tag-wrapper {
  display: flex;
  padding: 10px 15px 10px 18px;
}
.tag-wrapper a {
  color: #fff !important;
}
.tag-btn {
  display: inline-block;
  font-size: 0.725rem;
  line-height: 22px;
  height: 22px;
  border-radius: 10px;
  padding: 0 12px !important;
  background: linear-gradient(to right, #bf4643 100%, #6c9d8f 100%);
  margin-right: 0.5rem;
}
</style>
